<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>foamTimeAverage | Giskard&#39;s CFD Learning Tricks</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="在前面的一篇博文中，我介绍了fieldAverage这个functionObject的用法，其中提到， 可以用window这个参数来控制所计算的时均值的时间范围。如果 base = time且window = 10，那从第10s以后，每个时刻 t 输出的时均值其实相当于从 t-10 到 t 这个时间段内的时均值。但是，根据分析可以发现，这个时均值并不严格等价于从 t-10 时刻到 t 时刻某个场的">
<meta property="og:type" content="article">
<meta property="og:title" content="foamTimeAverage">
<meta property="og:url" content="http://xiaopingqiu.github.io/2015/05/31/foamTimeAverage/index.html">
<meta property="og:site_name" content="Giskard's CFD Learning Tricks">
<meta property="og:description" content="在前面的一篇博文中，我介绍了fieldAverage这个functionObject的用法，其中提到， 可以用window这个参数来控制所计算的时均值的时间范围。如果 base = time且window = 10，那从第10s以后，每个时刻 t 输出的时均值其实相当于从 t-10 到 t 这个时间段内的时均值。但是，根据分析可以发现，这个时均值并不严格等价于从 t-10 时刻到 t 时刻某个场的">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="foamTimeAverage">
<meta name="twitter:description" content="在前面的一篇博文中，我介绍了fieldAverage这个functionObject的用法，其中提到， 可以用window这个参数来控制所计算的时均值的时间范围。如果 base = time且window = 10，那从第10s以后，每个时刻 t 输出的时均值其实相当于从 t-10 到 t 这个时间段内的时均值。但是，根据分析可以发现，这个时均值并不严格等价于从 t-10 时刻到 t 时刻某个场的">
  
  
    <link rel="icon" href="/favicon.png">
  
  <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  
<!-- Google Analytics -->
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

##ga('create', '[object Object]', 'auto');
ga('create', 'UA-62501686-1', 'auto');
ga('send', 'pageview');

</script>
<!-- End Google Analytics -->


</head>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Giskard&#39;s CFD Learning Tricks</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">CFD and Scientific Computing</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
          <a class="main-nav-link" href="/atom.xml">Rss</a>
        
          <a class="main-nav-link" href="/about">About</a>
        
      </nav>
      <nav id="sub-nav">
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="q" value="site:http://xiaopingqiu.github.io"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-foamTimeAverage" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/05/31/foamTimeAverage/" class="article-date">
  <time datetime="2015-05-31T09:11:00.000Z" itemprop="datePublished">2015-05-31</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/OpenFOAM/">OpenFOAM</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      foamTimeAverage
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p> 在<a href="http://xiaopingqiu.github.io/2015/04/12/fieldAverage/" target="_blank" rel="external">前面的一篇博文</a>中，我介绍了<code>fieldAverage</code>这个<code>functionObject</code>的用法，其中提到， 可以用<code>window</code>这个参数来控制所计算的时均值的时间范围。如果 <code>base = time</code>且<code>window = 10</code>，那从第10s以后，每个时刻 t 输出的时均值其实相当于从 t-10 到 t 这个时间段内的时均值。但是，根据分析可以发现，这个时均值并不严格等价于从 t-10 时刻到 t 时刻某个场的时均值。有时候，需要从某个时刻才开始计算时均值，而<code>fieldAverage</code>没有参数可以控制从某个时刻才开始计算时间平均。于是我参照<code>OpenFOAM</code>的<code>patchAverage.C</code>的代码写了一个后处理程序，用来计算指定时间段内的某个场的时均值。</p>
 <a id="more"></a>
<h3 id="foamTimeAverage_简介">foamTimeAverage 简介</h3><p> <code>foamTimeAverage</code> 是一段简单的后处理程序，其功能是在算例运行结束以后，根据指定的时间段，从数据文件夹里循环读入指定时间段内指定场的数据，并计算该段时间的该指定场的时均值，结果将会输出到该时间段最后一个时刻的数据文件夹内。举例说：<br> <figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">foamTimeAverage <span class="tag">p</span> -<span class="tag">time</span> <span class="number">0.4</span>:<span class="number">0.5</span></span><br></pre></td></tr></table></figure></p>
<p> 将会计算<code>0.4 s-0.5 s</code>时间段内<code>p</code>的时均值，结果将输出到<code>0.5</code>内，时均值文件名为<code>p_mean</code>。这个程序只支持计算<code>volField</code>的时均值，不支持<code>surfaceField</code>。目前，这个程序只在<code>OpenFOAM-2.1.1</code>和<code>OpenFOAM-2.3.1</code>下通过可编译测试，运行的结果目前只在<code>OpenFOAM-2.1.1</code>下对<code>volScalarField</code>和<code>volVectorField</code>进行了测试。理论上讲，应该在其他版本的<code>OpenFOAM</code>下也可以正常编译和运行。</p>
<p> 以下是<code>foamTimeAverage</code>的代码：<br> <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*---------------------------------------------------------------------------*\</span><br><span class="line"> *=========                 |</span><br><span class="line"> *\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox</span><br><span class="line"> *\\     /   O peration     |</span><br><span class="line"> *\\    /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.</span><br><span class="line"> *\\   /     M anipulation  |</span><br><span class="line"> * -------------------------------------------------------------------------------</span><br><span class="line"> license</span><br><span class="line"> This file is part of OpenFOAM.</span><br><span class="line"></span><br><span class="line"> OpenFOAM is free software; you can redistribute it and/or modify it</span><br><span class="line"> under the terms of the GNU General Public License as published by the</span><br><span class="line"> Free Software Foundation; either version 2 of the License, or (at your</span><br><span class="line"> option) any later version.</span><br><span class="line"></span><br><span class="line"> OpenFOAM is distributed in the hope that it will be useful, but WITHOUT</span><br><span class="line"> ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</span><br><span class="line"> FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License</span><br><span class="line"> for more details.</span><br><span class="line"></span><br><span class="line"> You should have received a copy of the GNU General Public License</span><br><span class="line"> along with OpenFOAM; if not, write to the Free Software Foundation,</span><br><span class="line"> Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA</span><br><span class="line"></span><br><span class="line">Application</span><br><span class="line">   foamTimeAverage</span><br><span class="line"></span><br><span class="line">Author</span><br><span class="line">  Xiaoping Qiu </span><br><span class="line">  q.giskard@gmail.com</span><br><span class="line"></span><br><span class="line">Description</span><br><span class="line">Calculates the time average  of the specified volField over the specified time range.</span><br><span class="line"></span><br><span class="line">\*---------------------------------------------------------------------------*/</span></span><br><span class="line"></span><br><span class="line"><span class="preprocessor">#<span class="keyword">include</span> "fvCFD.H"</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">template</span>&lt;<span class="keyword">class</span> FieldType&gt;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">calcTimeAverage</span></span><br><span class="line"><span class="params">(</span><br><span class="line">    fvMesh&amp; mesh,</span><br><span class="line">    <span class="keyword">const</span> IOobject&amp; fieldHeader,</span><br><span class="line">    <span class="keyword">const</span> word&amp; fieldName,</span><br><span class="line">    Time&amp; runTime,</span><br><span class="line">    instantList&amp; timeDirs,</span><br><span class="line">    <span class="keyword">bool</span>&amp; done</span><br><span class="line">)</span></span><br><span class="line"></span>&#123;</span><br><span class="line">    label nfield = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">const</span> word meanFieldName = fieldName + <span class="string">"_mean"</span>; </span><br><span class="line"></span><br><span class="line">    <span class="comment">//Info &lt;&lt; "class name = " &lt;&lt; fieldHeader.headerClassName() &lt;&lt; endl;</span></span><br><span class="line">    <span class="comment">//Info &lt;&lt; "typeName = " &lt;&lt; FieldType::typeName &lt;&lt; endl;</span></span><br><span class="line">    <span class="keyword">if</span>(!done &amp;&amp; fieldHeader.headerClassName() == FieldType::typeName)</span><br><span class="line">    &#123;</span><br><span class="line">	<span class="function">FieldType <span class="title">dummy</span></span><br><span class="line">	    <span class="params">(</span><br><span class="line">		IOobject</span><br><span class="line">		(</span><br><span class="line">		    fieldName,</span><br><span class="line">		    runTime.timeName()</span>,</span><br><span class="line">		    mesh,</span><br><span class="line">		    IOobject::MUST_READ</span><br><span class="line">		),</span><br><span class="line">		mesh</span><br><span class="line">	    )</span>;</span><br><span class="line"></span><br><span class="line">	<span class="function">FieldType <span class="title">meanField</span></span><br><span class="line">	    <span class="params">(</span><br><span class="line">		IOobject</span><br><span class="line">		(</span><br><span class="line">		    meanFieldName,</span><br><span class="line">		    runTime.timeName()</span>,</span><br><span class="line">		    mesh,</span><br><span class="line">		    IOobject::NO_READ</span><br><span class="line">		),</span><br><span class="line">		dummy</span><br><span class="line">	    )</span>;</span><br><span class="line"></span><br><span class="line">	meanField *= scalar(<span class="number">0.0</span>);</span><br><span class="line"></span><br><span class="line">	forAll(timeDirs, timeI)</span><br><span class="line">	&#123;</span><br><span class="line">	    runTime.setTime(timeDirs[timeI], timeI);</span><br><span class="line">	    Info &lt;&lt; <span class="string">"Time = "</span> &lt;&lt; runTime.timeName() &lt;&lt;endl;</span><br><span class="line"></span><br><span class="line">	    <span class="function">IOobject <span class="title">io</span></span><br><span class="line">		<span class="params">(</span><br><span class="line">		    fieldName,</span><br><span class="line">		    runTime.timeName()</span>,</span><br><span class="line">		    mesh,</span><br><span class="line">		    IOobject::MUST_READ</span><br><span class="line">		)</span>;</span><br><span class="line"></span><br><span class="line">	    <span class="keyword">if</span> (io.headerOk())</span><br><span class="line">	    &#123;</span><br><span class="line">		mesh.readUpdate();</span><br><span class="line"></span><br><span class="line">		<span class="keyword">if</span>(!done &amp;&amp; io.headerClassName() == FieldType::typeName)</span><br><span class="line">		&#123;</span><br><span class="line">		    Info &lt;&lt; <span class="string">"   Reading "</span> &lt;&lt; io.headerClassName() &lt;&lt; <span class="string">" "</span> &lt;&lt;io.name() &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">		    <span class="function">FieldType <span class="title">field</span><span class="params">(io, mesh)</span></span>;</span><br><span class="line"></span><br><span class="line">		    meanField += field;</span><br><span class="line">		    nfield++;</span><br><span class="line">		&#125;</span><br><span class="line">	    &#125;</span><br><span class="line">	    <span class="keyword">else</span></span><br><span class="line">	    &#123;</span><br><span class="line">		Info &lt;&lt; <span class="string">"   No Field "</span> &lt;&lt; fieldName &lt;&lt; endl; </span><br><span class="line">	    &#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">if</span>(nfield &gt; <span class="number">0</span>)</span><br><span class="line">	&#123;</span><br><span class="line">	    Info &lt;&lt; <span class="string">"number of field = "</span> &lt;&lt; nfield &lt;&lt; endl;</span><br><span class="line">	    meanField /= nfield;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	Info&lt;&lt; <span class="string">"writing to timeDir "</span> &lt;&lt; runTime.timeName()  &lt;&lt; endl;</span><br><span class="line">	meanField.write();</span><br><span class="line">	done = <span class="keyword">true</span>;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// Main program:</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> *argv[])</span></span><br><span class="line"></span>&#123;</span><br><span class="line"></span><br><span class="line">    Foam::timeSelector::addOptions();</span><br><span class="line">    <span class="preprocessor">#<span class="keyword">include</span> "addRegionOption.H"</span></span><br><span class="line">    Foam::argList::validArgs.append(<span class="string">"fieldName"</span>);</span><br><span class="line"></span><br><span class="line"><span class="preprocessor">#   <span class="keyword">include</span> "setRootCase.H"</span></span><br><span class="line"><span class="preprocessor">#   <span class="keyword">include</span> "createTime.H"</span></span><br><span class="line">    instantList timeDirs = timeSelector::select0(runTime, args);</span><br><span class="line">    runTime.setTime(timeDirs[<span class="number">0</span>], <span class="number">0</span>);</span><br><span class="line"><span class="preprocessor">#   <span class="keyword">include</span> "createNamedMesh.H"</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// get filename from command line</span></span><br><span class="line">    <span class="keyword">const</span> word fieldName = args[<span class="number">1</span>];</span><br><span class="line">    <span class="keyword">bool</span> done = <span class="keyword">false</span>;</span><br><span class="line"></span><br><span class="line">    <span class="function">IOobject <span class="title">fieldHeader</span></span><br><span class="line">	<span class="params">(</span><br><span class="line">	    fieldName,</span><br><span class="line">	    runTime.timeName()</span>,</span><br><span class="line">	    mesh,</span><br><span class="line">	    IOobject::MUST_READ</span><br><span class="line">	)</span>;</span><br><span class="line">    <span class="keyword">if</span>(fieldHeader.headerOk())<span class="comment">//very important!</span></span><br><span class="line">    &#123;</span><br><span class="line">	calcTimeAverage&lt;volScalarField&gt;(mesh, fieldHeader, fieldName, runTime, timeDirs, done);</span><br><span class="line">	calcTimeAverage&lt;volVectorField&gt;(mesh, fieldHeader, fieldName, runTime, timeDirs, done);</span><br><span class="line">	calcTimeAverage&lt;volTensorField&gt;(mesh, fieldHeader, fieldName, runTime, timeDirs, done);</span><br><span class="line">	calcTimeAverage&lt;volSymmTensorField&gt;(mesh, fieldHeader, fieldName, runTime, timeDirs, done);</span><br><span class="line">	calcTimeAverage&lt;volSphericalTensorField&gt;(mesh, fieldHeader, fieldName, runTime, timeDirs, done);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">    &#123;</span><br><span class="line">	Info&lt;&lt; <span class="string">" Error! No field "</span> &lt;&lt; fieldName &lt;&lt; endl;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    Info&lt;&lt; <span class="string">"End\n"</span> &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// ************************************************************************* //</span></span><br></pre></td></tr></table></figure></p>
<p> 更详细的参考，包括编译和使用方法，见<a href="https://github.com/xiaopingqiu/foamTimeAverage" target="_blank" rel="external">代码的github页面</a>。</p>
<h3 id="一点说明">一点说明</h3><p> <code>foamTimeAverage</code> 这个程序有一个缺点，那就是只能根据输出的文件来计算时均值。举例说，假如算例的时间步长取<code>0.0001 s</code>，每<code>0.01 s</code> 输出一次，那<code>0.4 s-0.5 s</code>这个时间段的时均值就只涉及到<code>0.40s, 0.41s, 0.42s, ... 0.50s</code>这些时刻的值。有时候，如果想计算的是更精确的时均值，即<code>0.4000s, 0.4001s, 0.4002s ... 0.5000s</code>这些时刻的时均值，该怎么办呢？我没有实际测试过，但有一种方法我觉得可行，需要结合<code>fieldAverage</code>和<code>foamTimeAverage</code>来实现，具体操作如下：</p>
<ol>
<li><p>设置<code>fieldAverage</code>，注意将<code>resetOnOutput</code>设置为<code>true</code>，<code>outputControl</code>设置为<code>outputTime</code>，<code>base</code>设为<code>time</code>，<code>window</code>不需要设置，这样，应该就会在每一个输出的时间文件夹里输出一个时均值，这个时均值计算的上一次输出到下一次输出之间的时间段内的时均值，用上面的例子来说，即<code>0.5</code>文件夹内输出的<code>p</code>的时均值<code>pMean</code>是<code>0.4001s, 0.4002s, ... 0.5000s</code>这些时刻的<code>p</code>的时均值。</p>
</li>
<li><p>用<code>foamTimeAverage</code>计算指定时间段内<code>pMean</code>的时均值。举例说，<br><code>foamTimeAverage pMean -time 0.04:0.05</code> 计算的将是 <code>0.3001s, 0.3002s, ... 0.5000s</code>这些时刻的时均值，这是因为，0.04 文件夹内的<code>pMean</code>是 <code>0.3001s, 0.3002s, ... 0.4000s</code>的时均值，0.05 文件夹内的<code>pMean</code>是<code>0.4001s, 0.4002s, ... 0.5000s</code>时刻内的时均值。</p>
<p>用以上方法就可以实现计算指定时间段内同时精度更高的时均值了。<strong>再次申明一下，上述方法仅仅是我根据原理进行的推演，没有经过检验</strong>。</p>
</li>
</ol>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://xiaopingqiu.github.io/2015/05/31/foamTimeAverage/" data-id="cj2lay33r003dkkmb3sr47ne1" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/OpenFOAM/">OpenFOAM</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Postprocessing/">Postprocessing</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2015/06/14/OpenFOAM-on-win/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          在 Windows 7 下配置 OpenFOAM 运行环境
        
      </div>
    </a>
  
  
    <a href="/2015/05/17/twoPhaseEulerFoam2/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">twoPhaseEulerFoam 全解读之二</div>
    </a>
  
</nav>

  
</article>


<section id="comments">
  <!-- 多说评论框 start -->
  <div class="ds-thread" data-thread-key="post-foamTimeAverage" data-title="foamTimeAverage" data-url="http://xiaopingqiu.github.io/2015/05/31/foamTimeAverage/"></div>
  <!-- 多说评论框 end -->
  <!-- 多说公共JS代码 start (一个网页只需插入一次) -->
  <script type="text/javascript">
  var duoshuoQuery = {short_name:"xiaopingqiu"};
	(function() {
		var ds = document.createElement('script');
		ds.type = 'text/javascript';ds.async = true;
		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
		ds.charset = 'UTF-8';
		(document.getElementsByTagName('head')[0] 
		 || document.getElementsByTagName('body')[0]).appendChild(ds);
	})();
	</script>
  <!-- 多说公共JS代码 end -->
</section>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/C/">C++</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/DEM/">DEM</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/OpenFOAM/">OpenFOAM</a><span class="category-list-count">44</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Paraview/">Paraview</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/swak4Foam/">swak4Foam</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/test/">test</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/vim/">vim</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Boundary-conditions/">Boundary conditions</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/">C++</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CentOS/">CentOS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Code-Explained/">Code Explained</a><span class="tag-list-count">29</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/LES/">LES</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/LIGGGHTS/">LIGGGHTS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ODE/">ODE</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/OpenFOAM/">OpenFOAM</a><span class="tag-list-count">20</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Postprocessing/">Postprocessing</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Preprocessing/">Preprocessing</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RTS/">RTS</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TIL/">TIL</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Windows/">Windows</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/fvOptions/">fvOptions</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/groovyBC/">groovyBC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/paraview/">paraview</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/test/">test</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/thermophysicalModels/">thermophysicalModels</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/turbulence-model/">turbulence model</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vim/">vim</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/wall-functions/">wall functions</a><span class="tag-list-count">4</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Boundary-conditions/" style="font-size: 15.56px;">Boundary conditions</a><a href="/tags/C/" style="font-size: 11.11px;">C++</a><a href="/tags/CentOS/" style="font-size: 10px;">CentOS</a><a href="/tags/Code-Explained/" style="font-size: 20px;">Code Explained</a><a href="/tags/LES/" style="font-size: 10px;">LES</a><a href="/tags/LIGGGHTS/" style="font-size: 10px;">LIGGGHTS</a><a href="/tags/ODE/" style="font-size: 10px;">ODE</a><a href="/tags/OpenFOAM/" style="font-size: 18.89px;">OpenFOAM</a><a href="/tags/Postprocessing/" style="font-size: 17.78px;">Postprocessing</a><a href="/tags/Preprocessing/" style="font-size: 11.11px;">Preprocessing</a><a href="/tags/RTS/" style="font-size: 12.22px;">RTS</a><a href="/tags/TIL/" style="font-size: 10px;">TIL</a><a href="/tags/Windows/" style="font-size: 10px;">Windows</a><a href="/tags/fvOptions/" style="font-size: 11.11px;">fvOptions</a><a href="/tags/groovyBC/" style="font-size: 10px;">groovyBC</a><a href="/tags/paraview/" style="font-size: 10px;">paraview</a><a href="/tags/test/" style="font-size: 11.11px;">test</a><a href="/tags/thermophysicalModels/" style="font-size: 14.44px;">thermophysicalModels</a><a href="/tags/turbulence-model/" style="font-size: 16.67px;">turbulence model</a><a href="/tags/vim/" style="font-size: 10px;">vim</a><a href="/tags/wall-functions/" style="font-size: 13.33px;">wall functions</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/08/">八月 2016</a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/06/">六月 2016</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/05/">五月 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/04/">四月 2016</a><span class="archive-list-count">12</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/03/">三月 2016</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">十二月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">十一月 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/10/">十月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/09/">九月 2015</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/08/">八月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/06/">六月 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/05/">五月 2015</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/04/">四月 2015</a><span class="archive-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/05/12/duoshuoAnnouncement/">多说评论系统将停止提供服务</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewScritps/">Paraview 脚本一例</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewCamera/">Paraview 中有关 Camera 的操作两例</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewCustomFilter/">Paraview 中创建 Custom Filter</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewStreamLineOnSlice/">在 Paraview 中画截面上的流线</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 Giskard Q.<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

<script src="//dn-lbstatics.qbox.me/lbservice/busuanzi/2.0/busuanzi.mini.js"/></script>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/atom.xml" class="mobile-nav-link">Rss</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-62501686-1', 'auto');
  ga('send', 'pageview');

</script>

  </div>
<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</body>
</html>